package com.sinosoft.jwjw.component.service.imp.clueManage;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sinosoft.jwjw.component.mapper.clueManage.ClueBasicInfoMapper;
import com.sinosoft.jwjw.component.model.clueManage.ClueBasicInfo;
import com.sinosoft.jwjw.utils.ResultList;
import com.sinosoft.jwjw.utils.ResultPage;
import net.sf.json.JSONArray;

import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sinosoft.jwjw.base.BaseCrudMapper;
import com.sinosoft.jwjw.base.BaseCrudServiceImp;
import com.sinosoft.jwjw.component.service.clueManage.ClueBasicInfoService;

import java.util.HashMap;
import java.util.Map;

/**
 * 线索基本信息service层
 * @ver 系统自动生成代码
 */
@Service
public class ClueBasicServiceImp extends BaseCrudServiceImp<ClueBasicInfo,String> implements ClueBasicInfoService {

    @Autowired
    private ClueBasicInfoMapper clueBasicInfoMapper;

    @Override
    public BaseCrudMapper<ClueBasicInfo, String> getMapper() {
        return clueBasicInfoMapper;
    }

	@Override
	public int saveCule(ClueBasicInfo clueBasicInfo) {
		// TODO Auto-generated method stub
		return clueBasicInfoMapper.insert(clueBasicInfo);
	}

    @Override
    public ResultPage getListPage(int pageNum, int pageSize, String currentActiveNo, String acceptDateStartTime, String acceptDateEndTime, String clueNo, String clueName, String clueSourceCode) {
        ResultPage resultPage = new ResultPage();
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("currentActiveNo", currentActiveNo);
            params.put("clueNo", clueNo);
            params.put("clueName", clueName);
            params.put("clueSourceCode", clueSourceCode);
            params.put("acceptDateStartTime", acceptDateStartTime);
            params.put("acceptDateEndTime", acceptDateEndTime);
            Page page = PageHelper.startPage(pageNum, pageSize, true);
            JSONArray list = clueBasicInfoMapper.getListPage(params);
            resultPage.setCode(0);
            resultPage.setMsg("成功");
            resultPage.setPageIndex(pageNum);
            resultPage.setPageSize(pageSize);
            resultPage.setAllcount(page.getTotal());
            resultPage.setResult(list);
        } catch (Exception e) {
            resultPage.setCode(500);
            resultPage.setMsg("呀，网络不太好~");
            resultPage.setInnermsg(e.toString());
            resultPage.setPageIndex(pageNum);
            resultPage.setPageSize(pageSize);
            resultPage.setAllcount(0L);
            resultPage.setResult(new JSONArray());
        } finally {
            return resultPage;
        }
    }

    @Override
    public ResultList countBySource(String acceptDateStartTime, String acceptDateEndTime) {
        ResultList result = new ResultList();
        Map<String, Object> params = new HashMap<>();
        params.put("acceptDateStartTime", acceptDateStartTime);
        params.put("acceptDateEndTime", acceptDateEndTime);
        JSONArray list = clueBasicInfoMapper.countBySource(params);
        result.setCode(0);//成功
        result.setMsg("成功");
        result.setResult(list);
        return result;
    }
}
